package com.yin.myproject.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * Created by Eason on 2017/9/25.
 */
public class ProducerUtils {

//    private static Producer<String, String> producer;
//
//    static {
//        Properties props = new Properties();
//        props.put("bootstrap.servers", "172.168.102.130:9092");
//        props.put("acks", "all");
//        props.put("retries", 0);
//        props.put("batch.size", 16384);
//        props.put("linger.ms", 1);
//        props.put("buffer.memory", 33554432);
//        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
//        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
//        producer = new KafkaProducer<String, String>(props);
//    }
//
//    /**
//     * 发送信息
//     *
//     * @param topicName
//     * @param key
//     * @param value
//     */
//    public static void send(String topicName, String key, String value) {
//        producer.send(new ProducerRecord<String, String>(topicName, key, value));
//    }


    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "172.16.20.123:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 10; i++)
            producer.send(new ProducerRecord<>("qydproduction", "123", "123"));
    }
}
